for DHT sensor (that is, temperature and humidity sensor), here is the wiring for a 4-pin DHT sensor.

dht wiring

1st wire to vcc, 2nd wire is the data pin, it goes to a digital pin, 3rd pin is unused, 4th pin goes to ground.

NOTE: this code is based off the example code and modified to remove degrees Fahrenheit in the library provided via here. alternatively, you can search it up in the arduino program itself (sketch -> include libraries -> manage libraries)

for display purposes, I have added in the code for lcd into the program (you can find an example code of it here).

dht code

in this part of the code, we include the library DHT.h and LiquidCrystal_I2C.h, set the pin number for the dht data pin and declare what dht sensor and lcd model we are using. we also initialized the lcd and the dht sensor so that they can begin recording / displaying.

dht code

in the looping part of the program, we read the humidity first, followed by temperature in degree Celcius. We then check if the sensor has failed to read it. Typically, when it cant read properly, it's likely you connected the pins wrongly or programmed the pin to be in the wrong place. if your vcc and gnd pins are wrongly placed, you wont even be able to run the program. it will end the program at that point.

if it didnt fail to read, it will compute the temperature and humidity. After which, we display the temperature and humidity accordingly.

Here's the original code (with download link at image below!)

download here